﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CollaborationRoom>" %>
<%@ Import Namespace="ViewRes" %>
<script type="text/javascript">

    function loadMessages() {
        $("#divGrid").load('<%:Url.RouteUrl("Default",
                                           new
                                               {
                                                   controller = "Messages",
                                                   action = "MessagesByPage",
                                                   roomId = Model.CollaborationRoomId
                                               })%>');
        $('#newMessage').val('');
    }

    $(function() {
        $(".pager a").live("click", function() {
            var path = $(this).attr("href");
            var updateTargetId = $(this).attr("updatetargetid");
            $("#" + updateTargetId).load(path, function() {
            });

            return false;
        });

        $("#divGrid .deleteMessageLink").live("click", function() {
            var path = $(this).attr("href");
            $("#divGrid").load(path);
            return false;
        });

        $("#divGrid tr", this).live("hover", function() {
            $(this).find(".deleteMessageLink").toggle();
        });

        $("#newMessageContainer form").attr("onSuccess", "loadMessages();");
    });
</script>
<div>
    <div id="leftpanel_middle">
        <div>
            <div style="padding-left: 10px; padding-right: 30px;">
                <div id="divGrid">
                    <%
                        Html.RenderPartial("~/Views/Messages/MessagesListControl.ascx",
                                           Model.Messages.Where(m => m.DeletionDate == null).OrderByDescending(
                                               m => m.PubDate).ToPagedList(1, 10), ViewData);%>
                </div>
            </div>
        </div>
        <div>
            <h4 class="newMessage">
                <%:MessagesStrings.New%></h4>
            <div id="newMessageContainer">
                <%
                        using (Html.BeginRouteForm("Default", new {controller = "Messages", action = "Send"}))
                        {%>
                <%:Html.TextArea("message", new {id = "newMessage"})%>
                <%:Html.Hidden("roomId", Model.CollaborationRoomId)%>
                <div>
                    <input type="submit" value="<%:MessagesStrings.Send%>" style="margin-bottom: 40px;" />
                </div>
                <%
                        }%>
            </div>
        </div>
    </div>
</div>
